﻿namespace portfolio.Computation

type Vector2D =
    {dx: float; dy: float}

    /// Get the length of the vector
    member v.Length = sqrt(v.dx * v.dx + v.dy + v.dy)

    /// Get a vector scaled by factor K
    member v.Scale(k) = {dx = k*v.dx; dy = k*v.dy}

    /// Return a vector shifted by the given delta in the X coordinate
    member v.ShiftX(x) = {v with dx = v.dx + x}

    /// Return a vector shifted by the given delta in the Y coordinate
    member v.ShiftY(y) = {v with dy = v.dy + y}

    /// Return a vector shifted by the given distance in both directions
    member v.ShiftXY(x,y) = {dx = v.dx + x; dy = v.dy + y}

    /// Get the Zero Vector
    static member Zero = {dx = 0.0; dy = 0.0}

    /// Return a constant vector along the X axis
    static member ConstX(DX) = {dx = DX; dy = 0.0}

    /// Return a constant vector along the X axis
    static member ConstY(DY) = {dx = 0.0; dy = DY}

type Vector3D =
    {dx: float; dy: float; dz: float}

    /// Get the length of the vector
    member v.Length = sqrt(v.dx * v.dx + v.dy * v.dy + v.dz * v.dz)

    /// Get a vector scaled by factor K
    member v.Scale(k) = {dx = k*v.dx; dy = k*v.dy; dz = k*v.dz}

    /// Return a vector shifted by the given delta in the X coordinate
    member v.ShiftX(x) = {v with dx = v.dx + x}

    /// Return a vector shifted by the given delta in the Y coordinate
    member v.ShiftY(y) = {v with dy = v.dy + y}

    /// Return a vector shifted by the given delta in the Y coordinate
    member v.ShiftZ(z) = {v with dz = v.dz + z}

    /// Return a vector shifted by the given distance in both directions
    member v.ShiftXY(x,y) = {v with dx = v.dx + x; dy = v.dy + y}

    /// Return a vector shifted by the given distance in both directions
    member v.ShiftXZ(x,z) = {v with dx = v.dx + x; dz = v.dz + z}

    /// Return a vector shifted by the given distance in both directions
    member v.ShiftYZ(y,z) = {v with dy = v.dy + y; dz = v.dz + z}

    /// Return a vector shifted by the given distance in both directions
    member v.ShiftXYZ(x,y,z) = {dx = v.dx + x; dy = v.dy + y; dz = v.dz + z}

    /// Get the Zero Vector
    static member Zero = {dx = 0.0; dy = 0.0; dz = 0.0}

    /// Return a constant vector along the X axis
    static member ConstX(DX) = {dx = DX; dy = 0.0; dz = 0.0}

    /// Return a constant vector along the X axis
    static member ConstY(DY) = {dx = 0.0; dy = DY; dz = 0.0}

    /// Return a constant vector along the X axis
    static member ConstZ(DZ) = {dx = 0.0; dy = 0.0; dz = DZ}